﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SmartMosaic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Load += new EventHandler(Form1_Load);
            this.Closed += new EventHandler(Form1_Closed);
        }

        void Form1_Closed(object sender, EventArgs e)
        {
            deepZoomViewerControl1.Cleanup();
        }

        void Form1_Load(object sender, EventArgs e)
        {
            deepZoomViewerControl1.DeepZoomUrl = "http://211.189.20.163:8080/test7";

            //textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);

            //trackBar1.ValueChanged += new EventHandler(trackBar1_ValueChanged);

            Microsoft.WindowsCE.Forms.SystemSettings.ScreenOrientation = Microsoft.WindowsCE.Forms.ScreenOrientation.Angle90;
        }

        void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                //deepZoomViewerControl1.ZoomFactor = Convert.ToInt32(textBox1.Text);
            }
        }

        private void deepZoomViewerControl2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
                //deepZoomViewerControl1.ZoomFactor = Convert.ToInt32(textBox1.Text);
        }

        int count = 0;
        int origin = 0;
        int target = 0;

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            count = 1;
            Timer timer = new Timer();
            timer.Interval = 100;
            timer.Tick += new EventHandler(timer_Tick);

            origin = deepZoomViewerControl1.ZoomFactor;

            switch (trackBar1.Value)
            {
                case 1:
                    //deepZoomViewerControl1.ZoomFactor = (int)149;
                    target = 109;
                    break;

                case 2:
                    //deepZoomViewerControl1.ZoomFactor = (int)149 * 2;
                    target = 110 * 2;
                    break;

                case 3:
                    //deepZoomViewerControl1.ZoomFactor = (int)149 * 4;
                    target = 110 * 4;
                    break;

                case 4:
                    //deepZoomViewerControl1.ZoomFactor = (int)149 * 8;
                    target = 110 * 8;
                    break;

                case 5:
                    //deepZoomViewerControl1.ZoomFactor = (int)149 * 16;
                    target = 110 * 16;
                    break;

                case 6:
                    //deepZoomViewerControl1.ZoomFactor = (int)149 * 32;
                    target = 110 * 32;
                    break;
            }

            timer.Enabled = true;
        }

        void timer_Tick(object sender, EventArgs e)
        {
            int delta = Convert.ToInt32((target - origin) / 5.0);

            deepZoomViewerControl1.ZoomFactor = origin + (delta * count);

            count++;

            if (count == 5)
            {
                deepZoomViewerControl1.ZoomFactor = target;

                ((Timer)sender).Dispose();
            }
        }
    }
}